<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ page import="com.test.util.*"%>
<%@ page import="java.util.*"%>
<%@ page import="com.test.Constants"%>
<%@page import="com.test.clyq.service.VisitLogsService"%>
<%@page import="com.test.util2.TimeStamp"%>
<%@page import="com.test.clyq.entity.VisitLogsCountResult"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<script language="JavaScript" src="/static/js/chartsJs/FusionCharts.js"></script>
		<title>访问流量统计图</title>
	</head>
	<% 
	VisitLogsService visitLogsService = (VisitLogsService) Constants.ctx.getBean("visitLogsService");
	Map<String,Long> map_init = new HashMap<String,Long>();
	StringBuilder s_xml = new StringBuilder(500);

	String startTime = request.getParameter("startTime");
	String endTime = request.getParameter("endTime");
	String searchType = request.getParameter("searchType");
	if(startTime==null || "".equals(startTime)){
		startTime = DateUtils.getTime(-7)+"000000";
	}else{
		startTime=startTime.replaceAll("-", "")+"000000";
	}
	if(endTime==null || "".equals(endTime)){
		endTime=TimeStamp.getTime(TimeStamp.YYYYMMDD)+"235959";
	}else{
		endTime=endTime.replaceAll("-", "")+"000000";
	}
	int day_num=DateUtils.compareTime(DateUtils.toLong(startTime),DateUtils.toLong(endTime));
	long curr=DateUtils.toLong(startTime);
	
	for(int i=0;i<(day_num+1);i++){
		if(i!=0){
			curr=curr+(24*60*60*1000);
		}
		map_init.put(DateUtils.longToDateString(curr,"yyyyMMdd"),0l);
	}

	List<VisitLogsCountResult> vlcr_list= visitLogsService.getVisitLogByTime(startTime,endTime,searchType,null);
	if(vlcr_list!=null && !vlcr_list.isEmpty()){
		for(VisitLogsCountResult vlcr : vlcr_list){
			map_init.put(vlcr.getCategoryName(),vlcr.getCount());
		}
	}
	List arrayList = new ArrayList(map_init.entrySet()); 
	Collections.sort(arrayList, new TariffComparator());
	s_xml.append("<chart caption='总统计图' xAxisName='日期' showNames='0' yAxisName='统计数' showValues='0' decimals='0' formatNumberScale='0'>");
	for (Iterator it = arrayList.iterator();it.hasNext();) {
		Map.Entry entry = (Map.Entry)it.next(); 
		s_xml.append("<set label='"+entry.getKey()+"' value='"+entry.getValue()+"' />");
	}
	s_xml.append("</chart>");
	
	%>
	<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" style="font-size: 13px;">
		<div id="chartdiv" align="center">
		<!-- setDateXml -->
		</div>
		<script type="text/javascript">
		   var chart = new FusionCharts("/static/chartsSwf/Column3D.swf", "ChartId", "1024", "400", "0", "0");
		   chart.setDataXML("<%=s_xml.toString() %>");		   
		   chart.render("chartdiv");
		</script>
	</body>
</html>
